package com.five.dao.impl.backstage;

import com.five.dao.backstage.ChangeRoomDao;
import com.five.entity.backstage.TChangeRoom;
import com.five.util.DBUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class ChangeRoomDaoImpl implements ChangeRoomDao {
    @Override
    public List<Map> queryChangeRoom(Integer page, Integer limit, TChangeRoom tChangeRoom) {
        String sql = "select * from t_changeroom c \n" +
                    "left join t_ruzhudetail r on \n" +
                    "c.ruzhuid=r.ruzhuid\n" +
                    "where 1=1";
        if (tChangeRoom.getSoldroomid()!=null && tChangeRoom.getSoldroomid()!=""){
            sql+=" and oldroomid like '%"+tChangeRoom.getSoldroomid()+"%'";
        }
        if (tChangeRoom.getSnewroomid()!=null && tChangeRoom.getSnewroomid()!=""){
            sql+=" and newroomid like '%"+tChangeRoom.getSnewroomid()+"%'";
        }
        if (tChangeRoom.getBtime()!=null && tChangeRoom.getBtime()!="" && tChangeRoom.getEtime()!=null && tChangeRoom.getEtime()!=""){
            sql+=" and time>'"+tChangeRoom.getBtime()+"' and time<'"+tChangeRoom.getEtime()+"'";
        }
        sql+=" limit ?,?";
        List<Map> maps = DBUtil.queryMap(sql, (page - 1) * limit, limit);
        return maps;
    }

    @Override
    public int count(TChangeRoom tChangeRoom) {
        String sql = "select count(*) a from t_changeroom c \n" +
                    "left join t_ruzhudetail r on \n" +
                    "c.ruzhuid=r.ruzhuid\n" +
                    "where 1=1";
        if (tChangeRoom.getSoldroomid()!=null && tChangeRoom.getSoldroomid()!=""){
            sql+=" and oldroomid like '%"+tChangeRoom.getSoldroomid()+"%'";
        }
        if (tChangeRoom.getSnewroomid()!=null && tChangeRoom.getSnewroomid()!=""){
            sql+=" and newroomid like '%"+tChangeRoom.getSnewroomid()+"%'";
        }
        if (tChangeRoom.getBtime()!=null && tChangeRoom.getBtime()!="" && tChangeRoom.getEtime()!=null && tChangeRoom.getEtime()!=""){
            sql+=" and time>'"+tChangeRoom.getBtime()+"' and time<'"+tChangeRoom.getEtime()+"'";
        }
        List<Map> maps = DBUtil.queryMap(sql);
        String s = maps.get(0).get("a") + "";
        int i = Integer.parseInt(s);
        return i;
    }
}
